package chapter19;

import chapter18.OSExecute;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/4/2 21:26
 */
enum Explore {HERE, THERE}

public class Reflection {
    public static Set<String> analyze(Class<?> enumClass) {
        System.out.println("---- analyzing " + enumClass + "------");
        System.out.println("interfaces:");
        for (Type type : enumClass.getGenericInterfaces()) {
            System.out.println(type);
        }

        System.out.println("Base: " + enumClass.getSuperclass());
        System.out.println("methods:");
        Set<String> methods = new TreeSet<>();
        for (Method method : enumClass.getMethods()) {
            methods.add(method.getName());
        }
        System.out.println(methods);
        return methods;
    }

    public static void main(String[] args) {
        Set<String> exploreMethods = analyze(Explore.class);
        Set<String> enumMethods = analyze(Enum.class);
        System.out.println("explore.containsAll(Enum)?" + enumMethods.containsAll(enumMethods));
        System.out.println("explore.removeAll(Enum):");
        System.out.println(exploreMethods.removeAll(enumMethods));
        System.out.println(exploreMethods);
        OSExecute.command("javap Explore");
    }
}
